#include "model_class.h"

#include "generic_bitwise_templates.h"

namespace BitWin
{


int Model::rowCount(const QModelIndex& parent) const
{
    if (parent.isValid())
        return 0; // See parent class doc
    
    return _rows.size();
}

int Model::columnCount(const QModelIndex& parent) const
{
    if (parent.isValid())
        return 0; // See parent class doc
    
    return _columns.size();
}

QVariant Model::data(const QModelIndex& index, int role) const
{
    Row* row = _rows[index.row()].data();
    Column* column = _columns[index.column()].data();
    
    return column->data(
        role, row,
        _data.value(row->wordNo(), GenericBitwise::empty())
    );
}

QVariant Model::headerData(
    int section, Qt::Orientation orientation, int role
) const
{
    if (Qt::DisplayRole == role)
        switch (orientation)
        {
            case Qt::Horizontal:
                return _columns[section]->title();
            case Qt::Vertical:
                return _rows[section]->title();
            default: // We should never go here!
                return QVariant();
        }
    
    return QAbstractTableModel::headerData(section, orientation, role);
}

Model::Model(const PRowList& rows_, const PColumnList& columns_):
    _rows(rows_), _columns(columns_)
{}


} // BitWin namespace end
